Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c-mode: respect user-defined tab width for indentation #29

Merged
merged 1 commit into from
Jan 18, 2025

Conversation

dhennigar
Copy link

c-mode: Respect user-define tab width for indentation

This patch updates getindent to use the current buffer’s tab width
(curbp->b_tabw) when calculating indentation levels, instead of
always assuming 8 columns.

It ensures that c-mode behaves correctly with user-configurable tab
widths set via set-tab-width, while keeping the default behavior
KNF-compliant.

@troglobit
Copy link
Owner

Could you please include an example, preferably in the commit message, of how to replicate the problem your patch fixes? It may be evident to you, but for a reviewer it's very difficult to guess what it is you've seen.

Example:
1. set a custom tab width via `set-tab-width` (e.g., 4).
2. open c-mode, type of block of C code, and indent.

Expected behavior: One tab character per indentation level (or spaces if no-tab-mode enabled).
Actual behavior: Multiple tabs/spaces inserted to reach an indentation of 8 columns.

This patch updates `getindent` to respect the user-defined tab width
(`curbp->b_tabw`) when calculating indentation levels, instead of
always assuming 8 columns.

Previously, when the user set `set-tab-width` to 4, `c-mode` would
request 8 columns of indentation, resulting in two tab characters
being inserted instead of one. This caused incorrect indentation
for KNF-compliant code.
@dhennigar
Copy link
Author

I've updated the commit message with an example of how to replicate the issue. Let me know if you need further details!

@troglobit
Copy link
Owner

Thanks, replicated, good fix!

@troglobit troglobit merged commit dd29cb3 into troglobit:master Jan 18, 2025
4 checks passed
@dhennigar dhennigar deleted the cmode-tab-handling branch January 19, 2025 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants